<?php include $this->admin_tpl('meta');?>
<title>数据还原 - YzmCMS内容管理系统</title>
</head>
<body>
<nav class="breadcrumb"><i class="yzm-iconfont yzm-iconai-home"></i> 首页 <span class="c-gray en">&gt;</span> 数据管理 <span class="c-gray en">&gt;</span> 数据还原 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="yzm-iconfont yzm-iconshuaxin"></i></a></nav>
<div class="page-container">
   <div class="explain light"> 
      <p><span class="yzm-iconfont yzm-iconshuoming"></span>数据备份文件保存于“/cache/databack/”目录，如需恢复以往数据，请将备份文件放置到该目录即可.</p>
   </div>
	<table class="table table-border table-bg mt-20 table-hover">
		<thead>
			<tr class="text-c">
				<th>文件名称</th>
				<th>文件大小</th>
				<th>备份时间</th>
				<th>卷号</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
			<?php 
			   foreach($data as $val){
			 ?>
			<tr class="text-c">
				<td><?php echo $val['filename'];?></td>
				<td><?php echo $val['filesize'];?></td>
				<td><?php echo $val['backtime'];?></td>
				<td><?php echo $val['part'];?></td>
				<td class="td-manage">
					<a title="还原" href="javascript:;" onclick="databack_import('<?php echo U('import',array('random'=>$val['random'],'time'=>$val['time']));?>', '<?php echo $val['backtime'];?>')" class="btn-mini btn-primary" style="text-decoration:none">还原</a> 
					<a title="下载" href="<?php echo U('databack_down',array('random'=>$val['random'],'time'=>$val['time'],'part'=>$val['part']));?>" class="btn-mini btn-success ml-5">下载</a> 
					<a title="删除" href="javascript:;" onclick="yzm_confirm('<?php echo U('databack_del',array('random'=>$val['random'],'time'=>$val['time']));?>', '确定要删除【<?php echo $val['backtime'];?>】的数据吗？', 1)" class="btn-mini btn-danger ml-5">删除</a>
				</td>
			</tr>
			<?php 
			   }		 
			?>	
		</tbody>
	</table>
	<?php if(!$data){ ?><div class="yzm_no_data"><i class="yzm-iconfont yzm-iconshuoming"></i> 暂无备份数据</div><?php } ?>
</div>
<?php include $this->admin_tpl('footer');?>
<script type="text/javascript">
function databack_import(url, title) {
	layer.confirm('确定要还原【'+title+'】时的数据吗？', {title:"操作提示", icon:0}, function(index){
		layer.msg('<span id="yzm_message">开始请求服务器……</span>', {icon:16, shade:0.21, time:false});
	    $.ajax({
	        type: 'GET',
	        url: url, 
		    dataType: "json", 
	        success: function (msg) {
				if(msg.status == 1){
					$("#yzm_message").html(msg.message);
					yzm_dorequest(msg.data.part, msg.data.start);
			    }else{
			    	layer.alert(msg.message, {icon:2});
				}
	        }
	    })
	});
}

function yzm_dorequest(part, start) {
	$.ajax({
        type: 'POST',
        url: '<?php echo U('import');?>', 
        data: {"part":part, "start":start, "yzm_csrf_token":yzm_csrf_token},
	    dataType: "json", 
        success: function (msg) {
			if(msg.status == 1){
				layer.msg(msg.message, {icon:1, time:1500});
		    }else if(msg.status == 2){
		    	$("#yzm_message").html(msg.message);
				yzm_dorequest(msg.data.part, msg.data.start);
			}else{
				layer.alert(msg.message, {icon:2});
			}
        }
    })
}
</script>
</body>
</html>